Skip to content

Reorg introduce api package containing Entry interface#401

Open
steiler wants to merge 14 commits intomainfrom
reorgIntroduceAPI
Open

Reorg introduce api package containing Entry interface#401
steiler wants to merge 14 commits intomainfrom
reorgIntroduceAPI

Conversation

@steiler
Copy link
Collaborator

@steiler steiler commented Feb 19, 2026

Reorganizes the tree package by introducing a new pkg/tree/api surface and a pkg/tree/consts package, then updates the codebase to use those exported interfaces, types, and constants.

  • Adds a dedicated API layer (pkg/tree/api) with Entry, LeafVariants, delete-path types, and non-revertive tracking; introduces pkg/tree/ops helpers (e.g., GetByOwner) and an ops interface.
  • Moves tree constants to pkg/tree/consts and replaces many direct tree.RunningIntentName/RunningValuesPrio/Replace* usages with consts equivalents across datastore, targets, server, and tests.
  • Refactors core tree implementation to use the new API types: method visibility changes (e.g., ShouldDelete, GetOrCreateChilds, ToJsonInternal), LeafVariants accessors, and TreeContext now exposing SchemaClient, ExplicitDeletes, and NonRevertiveInfo.
  • Updates mocks and generated code to reflect new API package paths and added interface methods; adds a new mock for SdcpbPath.
  • Adjusts update/path handling with SdcpbPath() and updates callers, plus broad test updates to match new APIs and constants.

@steiler steiler requested a review from a team as a code owner February 19, 2026 14:24
Copy link
Contributor

@faebr faebr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the interface separation from the stateless ops. I always struggled to fully understand sharedEntryAttributes and this breaks it down! I assume the commented out functions in entry.go are the ones you will still implement right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the leaf_variants also be parts of the api / interface package or would it make sense to take this implementation into another package so to only have the interface definitions in the api package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible... lets add an issue to investigate that. Nothing I would want to also squeeze into this PR.

github.com/sdcio/logger v0.0.3
github.com/sdcio/schema-server v0.0.34
github.com/sdcio/sdc-protos v0.0.50
github.com/sdcio/sdc-protos v0.0.51-0.20260304120533-f0e62d96331e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess sdc-protos should be tagged and this updated before this PR is merged

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes exactly

explicitDeletes *sdcpb.PathSet
previouslyApplied bool
// revertPaths paths that are meant to be reverted. This is used for non-revertive intents.
revertPaths []*sdcpb.Path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably discuss if we want a slice of pointers - imo we should avoid it where possible but that probably is a bigger job to refactor

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe open an issue for this

}

deviationTree.GetDeviations(ctx, deviationChan)
dpc := ops.NewGetDeviationConfig(deviationChan)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if we are creating a config to be passed to a processor we should use the config struct directly as it is self documenting, and follows go more closely

}
// apply delete marker, setting owner delete flag on running intent
err = tree.NewOwnerDeleteMarker(tree.NewOwnerDeleteMarkerTaskConfig(tree.RunningIntentName, false)).Run(deleteRoot, d.taskPool)
err = processors.NewOwnerDeleteMarker(processors.NewOwnerDeleteMarkerTaskConfig(consts.RunningIntentName, false)).Run(deleteRoot, d.taskPool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous - here it makes it hard to know what false means, but using the struct directly would give some documentation

)

// GetDeletes calculate the deletes that need to be send to the device.
func GetDeletes(e api.Entry, deletes types.DeleteEntriesList, aggregatePaths bool) (types.DeleteEntriesList, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we accept the deletes list as an input here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ment to be a recursive function... To reduce allocation of DeleteEntriesList the result list is meant to be carried forward.
refactored with an internal function that takes that params list and the external call that inits an empty list.

// if s is a presence container but has active childs, it should not be treated as a presence
// container, hence the leafvariants should not be processed. For presence container with
// childs the TypedValue.empty_val in the presence container is irrelevant.
if dt.entry.GetSchema().GetContainer().GetIsPresence() && len(dt.entry.GetChilds(types.DescendMethodActiveChilds)) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor dt.entry.GetChilds() out to remove additional recomputation as it is also needed later on

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't there also proto functions in other files too? Other duplicates should probably be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No only the adapters that utilize these functions and adapt to the different interfaces

steiler added 3 commits March 13, 2026 11:38
…centralize dispatch

- extract entry validators into dedicated files (range, length, pattern, mandatory, min/max-elements)
- keep validate package entrypoint focused on orchestration/result aggregation
- introduce dedicated validator dispatch/registry file with shared ValidationFunc signature
- precompute active validators once from config and pass through recursive processor tasks
- simplify recursive validation path by executing only active validator functions per entry
@steiler steiler force-pushed the reorgIntroduceAPI branch from e2324c9 to eddffb1 Compare March 13, 2026 15:54
@codecov
Copy link

codecov bot commented Mar 13, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants